﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

#if NETFX_CORE
using Windows.ApplicationModel.Resources;

#endif

namespace StyleMVVM.Validation.Impl.Fluent
{
	public class FluentPropertySetValue<T, TProp> : IFluentValueProvider<T>
	{
		private readonly IEnumerable<string> expressions;
		private string displayString;

		public FluentPropertySetValue(IEnumerable<string> expressions)
		{
			this.expressions = expressions;
		}

		public Expression GenerateExpression(IFluentExpressionProvider propertyExpressionProvider)
		{
			List<Expression> propertyExpressions = new List<Expression>();

			foreach (string propertyName in expressions)
			{
				propertyExpressions.Add(propertyExpressionProvider.GetPropertyExpression(propertyName));

				displayString += propertyName + ", ";
			}

			if (!string.IsNullOrEmpty(displayString))
			{
				displayString = displayString.TrimEnd(',');
			}

			return Expression.NewArrayInit(typeof(TProp), propertyExpressions);
		}

		public string GenerateDisplayString(ResourceLoader loader)
		{
			return displayString;
		}
	}
}